//
//  User.m
//  QSBK
//
//  Created by Eric Wang on 4/20/15.
//  Copyright (c) 2015 Eric Wang. All rights reserved.
//

#import "User.h"

@implementation User
-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];
    if(self)
    {
        _last_visited_at = [aDecoder decodeObjectForKey:@"last_visited_at"];
        //_created_at = [aDecoder decodeObjectForKey:@"created_at"];
        _stater = [aDecoder decodeObjectForKey:@"stater"];
        _last_device = [aDecoder decodeObjectForKey:@"last_device"];
        _role = [aDecoder decodeObjectForKey:@"role"];
        _login = [aDecoder decodeObjectForKey:@"login"];
        _user_id = [aDecoder decodeObjectForKey:@"ID"];
        _icon = [aDecoder decodeObjectForKey:@"icon"];
        _email = [aDecoder decodeObjectForKey:@"email"];
        _longitude = [aDecoder decodeObjectForKey:@"longitude"] ;
        _latitude = [aDecoder decodeObjectForKey:@"latitude"] ;
        _articleTotal = [aDecoder decodeObjectForKey:@"articleTotal"];
        _sex = [aDecoder decodeObjectForKey:@"sex"];
        _bigImage = [aDecoder decodeObjectForKey:@"bigImage"];
    }
    return self;
}
-(void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:_last_visited_at forKey:@"last_visited_at"];
    //[aCoder encodeObject:_created_at forKey:@"created_at"];
    [aCoder encodeObject:_stater forKey:@"stater"];
    [aCoder encodeObject:_last_device forKey:@"last_device"];
    [aCoder encodeObject:_role forKey:@"role"];
    [aCoder encodeObject:_login forKey:@"login"];
    [aCoder encodeObject:_user_id forKey:@"ID"];
    [aCoder encodeObject:_icon forKey:@"icon"];
    [aCoder encodeObject:_email forKey:@"email"];
    [aCoder encodeObject:_longitude forKey:@"longitude"];
    [aCoder encodeObject:_latitude forKey:@"latitude"];
    [aCoder encodeObject:_articleTotal forKey:@"articleTotal"];
    [aCoder encodeObject:_sex forKey:@"sex"];
    [aCoder encodeObject:_bigImage forKey:@"bigImage"];
    
}



-(void)setLast_device:(NSString *)last_device
{
    if([last_device isEqual:[NSNull null]]||[last_device isEqualToString:@""])
    {
        _last_device = nil;
    }else{
        _last_device = last_device;
    }
}
-(void)setLast_visited_at:(NSString *)last_visited_at
{
    if([last_visited_at isEqual:[NSNull null]])
    {
        _last_visited_at = nil;
    }else{
        _last_visited_at = last_visited_at;
    }
}
-(void)setStater:(NSString *)stater
{
    if([stater isEqual:[NSNull null]]||[stater isEqualToString:@""])
    {
        _stater = nil;
    }else{
        _stater = stater;
    }
}
//-(void)setCreated_at:(NSString *)created_at
//{
//    if([created_at isEqual:[NSNull null]])
//    {
//        _created_at = nil;
//    }else{
//        _created_at = created_at;
//    }
//}
-(void)setRole:(NSString *)role
{
    if([role isEqual:[NSNull null]]||[role isEqualToString:@""])
    {
        _role = nil;
    }else{
        _role = role;
    }
}
-(void)setLogin:(NSString *)login
{
    if([login isEqual:[NSNull null]]||[login isEqualToString:@""])
    {
        _login = nil;
    }else{
        _login = login;
    }
}
-(void)setUser_id:(NSNumber *)user_id
{
    if([user_id isEqual:[NSNull null]])
    {
        _user_id = @0;
    }else{
        
        _user_id = user_id;
        
        
    }
}
-(void)setIcon:(NSString *)icon
{
    if([icon isEqual:[NSNull null]]||[icon isEqualToString:@""])
    {
        _icon = nil;
        
    }else{
        _icon = [NSString stringWithFormat:@"http://localhost:8888/thinkphp_3.2.3/users/%d/head/%@",[_user_id intValue],icon];
    }
}
-(void)setEmail:(NSString *)email
{
    if([email isEqual:[NSNull null]]||[email isEqualToString:@""])
    {
        _email = nil;
    }else{
        _email = email;
    }
        
}
-(void)setLongitude:(NSNumber *)longitude
{
    if([longitude isEqual:[NSNull null]])
    {
        _longitude = nil;
    }else{
        _longitude = longitude;
    }
}
-(void)setLatitude:(NSNumber *)latitude
{
    if([latitude isEqual:[NSNull null]])
    {
        _latitude = nil;
    }else{
        _latitude = latitude;
    }
}
-(void)setArticleTotal:(NSNumber *)articleTotal
{
    if([articleTotal isEqual:[NSNull null]])
    {
        _articleTotal = nil;
    }else{
        _articleTotal = articleTotal;
    }
}

-(void)setToken:(NSString *)token
{
    if([token isEqual:[NSNull null]]||[token isEqualToString:@""])
    {
        _token = nil;
    }else{
        _token = token;
    }
}

-(void)setSex:(NSNumber *)sex
{
    if([sex isEqual:[NSNull null]])
    {
        _sex = nil;
    }else{
        _sex = sex;
    }
}
-(void)setBigImage:(NSString *)bigImage
{
    if([bigImage isEqual:[NSNull null]]||[bigImage isEqualToString:@""])
    {
        _bigImage = nil;
    }else{
        _bigImage = bigImage;
    }
}
@end